'''

Case Type： 数据库系统
Case Name： 对同一备节点并行build
Create At:  2020/09/08
@zou_jialiang0505328126
Descption: 1、打开两个备节点主机session，同时执行build；

history：
created： 2020/09/08  created by @wan005
'''
import os
import unittest
from yat.test import Node
import time
import _thread
import queue
from yat.test import macro

import sys

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import *
from testcase.utils.Common import Common
from testcase.utils.ComThread import *
from testcase.utils.Constant import *


class KillDbPid(unittest.TestCase):
    sh = CommonSH('PrimaryDbUser')
    shsta = CommonSH('Standby1DbUser')
    nodes_tuple = ('PrimaryDbUser', 'Standby1DbUser', 'Standby2DbUser')

    @RestartDbCluster(*nodes_tuple)
    def setUp(self):
        self.log = Logger()
        self.log.info('------------Opengauss_Reliability_Dbsys_Case162.py start------------')
        self.dbPrimaryrootNode = Node(node='PrimaryRoot')
        self.PrimaryDbUser = Node(node='PrimaryDbUser')
        self.Standby1Root = Node(node='Standby1Root')
        self.Standby1DbUser = Node(node='Standby1DbUser')
        self.com = Common('PrimaryDbUser')
        self.Constant = Constant()

    def test_kill_db_pid(self):
        self.log.info('---------------------build 1---------------------------------')
        stop_thread = ComThread(self.shsta.executeGsctl, args=('build', self.Constant.REBUILD_SUCCESS_MSG))
        stop_thread.start()
        time.sleep(2)

        self.log.info('---------------------build 2---------------------------------')
        res2 = self.shsta.executeGsctl('build', self.Constant.REBUILD_SUCCESS_MSG)
        self.assertFalse(res2)

        stop_thread.join()
        stop_result = stop_thread.get_result()
        self.log.info(stop_result)
        self.assertTrue(stop_result)

    def tearDown(self):
        self.log.info('this is tearDown')
